$().ready(function () {
    validateRule();
});
$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function onTypeChange() {
    validateRule();
}

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/member/manage/update",
        data: $('#memberForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("设置折扣成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                if (data.msg) {
                    parent.layer.alert(data.msg)
                } else {
                    window.location.href = "/";
                }
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#memberForm").validate({
        rules: {
            discountStatus: {
                required: true,
            },
            discount: {
                required: true
            }
        },
        messages: {
            discountStatus: {
                required: icon + "密码不能为空",
            },
            discount: {
                required: icon + "密码不能为空",
            }
        }
    })
}